unit u_resennemi;

interface

type

  r_ennemi = record
    x, y, z : integer;
    i, j : integer;
    typ : string;
  end;

  t_ennemi = Array of r_ennemi;

  c_res_ennemi = class
    private
      ennemi_tab : t_ennemi;
    public
      procedure get_ennemi_info(var inf : t_ennemi);
      procedure get_ennemi_by_typ(_typ : string; var inf : t_ennemi);
      procedure change_ennemi_pos(last_x, last_y, last_z, new_x, new_y, new_z : integer);
      procedure add_ennemi(n_x, n_y, n_z, i, j : integer; typ : string);
      procedure del_ennemi_pos(pos_x, pos_y, pos_z : integer);
      procedure del_ennemi_ij(i, j : integer);
      constructor create;
  end;

implementation

  constructor c_res_ennemi.create;
    begin
      inherited create;
      SetLength(ennemi_tab, 0);
    end;

  procedure c_res_ennemi.change_ennemi_pos(last_x, last_y, last_z, new_x, new_y, new_z : integer);
  var
    i : integer;
    begin
      i := 0;
      if Length(ennemi_tab) <> 0 then
        while (i < Length(ennemi_tab)) and
        not((ennemi_tab[i].x = last_x) and (ennemi_tab[i].y = last_y) and (ennemi_tab[i].z = last_z)) do
          i := i + 1;
        if i <> Length(ennemi_tab) then
          begin
            ennemi_tab[i].x := new_x;
            ennemi_tab[i].y := new_y;
            ennemi_tab[i].z := new_z;
          end;
    end;

  procedure c_res_ennemi.add_ennemi(n_x, n_y, n_z, i, j : Integer; typ : string);
  var
    x : integer;
    begin
      x := Length(ennemi_tab);
      SetLength(ennemi_tab, x + 1);
      ennemi_tab[x].x := n_x;
      ennemi_tab[x].y := n_y;
      ennemi_tab[x].z := n_z;
      ennemi_tab[x].typ := typ;
      ennemi_tab[x].i := i;
      ennemi_tab[x].j := j;
    end;

  procedure c_res_ennemi.del_ennemi_pos(pos_x, pos_y, pos_z : Integer);
  var
    i, j, len : integer;
    begin
      i := 0;
      while (i < Length(ennemi_tab)) and
      not((ennemi_tab[i].x = pos_x) and (ennemi_tab[i].y = pos_y) and (ennemi_tab[i].z = pos_z)) do
        i := i + 1;
      if Length(ennemi_tab) <> i then
        begin
          for j := i to Length(ennemi_tab) - 2 do
            ennemi_tab[j] := ennemi_tab[j + 1];
          SetLength(ennemi_tab, length(ennemi_tab) - 1);
        end;
    end;

  procedure c_res_ennemi.del_ennemi_ij(i, j : integer);                
  var
    x, y, len : integer;
    begin
      x := 0;
      while (x < Length(ennemi_tab)) and
      not((ennemi_tab[x].j = j) and (ennemi_tab[x].i = i)) do
        x := x + 1;
      if Length(ennemi_tab) <> x then
        begin
          for y := x to Length(ennemi_tab) - 2 do
            ennemi_tab[y] := ennemi_tab[y + 1];
          SetLength(ennemi_tab, length(ennemi_tab) - 1);
        end;
    end;


  procedure c_res_ennemi.get_ennemi_info(var inf : t_ennemi);
    begin
      inf := ennemi_tab;
    end;

  procedure c_res_ennemi.get_ennemi_by_typ(_typ: string; var inf: t_ennemi);
  var
  i, len : Integer;
    begin
      SetLength(inf, 0);
      len := 0;
      for i := 0 to Length(ennemi_tab) - 1 do
        if ennemi_tab[i].typ = _typ then
          begin
            len := len + 1;
            SetLength(inf, len);
            inf[len - 1] := ennemi_tab[i];
          end;
    end;

end.

